cssnodedeclaration: Add possibility to set the name
authorBenjamin Otte <otte@redhat.com>
Fri, 4 Sep 2015 17:38:50 +0000 (19:38 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 22 Oct 2015 14:35:14 +0000 (16:35 +0200)
This is supposed to be a replacement for setting the type. So far, both
options are possible - either will unset the other.

gtk/gtkcssnodedeclaration.c
gtk/gtkcssnodedeclarationprivate.h

index da1c944bd357c581c79df8bc981f3bd1ac4b61d7..6d861fb448a849fe272319ba9befd1a47b8a32a7 100644 (file)
@@ -33,6 +33,7 @@ struct _GtkCssNodeDeclaration {
   guint refcount;
   GtkJunctionSides junction_sides;
   GType type;
+  const /* interned */ char *name;
   const /* interned */ char *id;
   GtkStateFlags state;
   guint n_classes;
@@ -118,6 +119,9 @@ gtk_css_node_declaration_new (void)
     1, /* need to own a ref ourselves so the copy-on-write path kicks in when people change things */
     0,
     0,
+    NULL,
+    NULL,
+    0,
     0,
     0
   };
@@ -166,10 +170,12 @@ gboolean
 gtk_css_node_declaration_set_type (GtkCssNodeDeclaration **decl,
                                    GType                   type)
 {
-  if ((*decl)->type == type)
+  if ((*decl)->type == type &&
+      (*decl)->name == NULL)
     return FALSE;
 
   gtk_css_node_declaration_make_writable (decl);
+  (*decl)->name = NULL;
   (*decl)->type = type;
 
   return TRUE;
@@ -181,6 +187,27 @@ gtk_css_node_declaration_get_type (const GtkCssNodeDeclaration *decl)
   return decl->type;
 }
 
+gboolean
+gtk_css_node_declaration_set_name (GtkCssNodeDeclaration   **decl,
+                                   /*interned*/ const char  *name)
+{
+  if ((*decl)->type == 0 &&
+      (*decl)->name == name)
+    return FALSE;
+
+  gtk_css_node_declaration_make_writable (decl);
+  (*decl)->type = 0;
+  (*decl)->name = name;
+
+  return TRUE;
+}
+
+/*interned*/ const char *
+gtk_css_node_declaration_get_name (const GtkCssNodeDeclaration *decl)
+{
+  return decl->name;
+}
+
 gboolean
 gtk_css_node_declaration_set_id (GtkCssNodeDeclaration **decl,
                                  const char             *id)
@@ -510,6 +537,7 @@ gtk_css_node_declaration_hash (gconstpointer elem)
   guint hash, i;
   
   hash = (guint) decl->type;
+  hash ^= GPOINTER_TO_UINT (decl->name);
   hash <<= 5;
   hash ^= GPOINTER_TO_UINT (decl->id);
 
@@ -550,6 +578,9 @@ gtk_css_node_declaration_equal (gconstpointer elem1,
   if (decl1->type != decl2->type)
     return FALSE;
 
+  if (decl1->name != decl2->name)
+    return FALSE;
+
   if (decl1->state != decl2->state)
     return FALSE;
 
index 066b8e205cbc525fa731055dddf981c4ae0bbd0f..a72111ab37fd3941526a9e8b8d0b865987df3278 100644 (file)
@@ -34,6 +34,9 @@ GtkJunctionSides        gtk_css_node_declaration_get_junction_sides     (const G
 gboolean                gtk_css_node_declaration_set_type               (GtkCssNodeDeclaration        **decl,
                                                                          GType                          type);
 GType                   gtk_css_node_declaration_get_type               (const GtkCssNodeDeclaration   *decl);
+gboolean                gtk_css_node_declaration_set_name               (GtkCssNodeDeclaration        **decl,
+                                                                         /*interned*/ const char       *name);
+/*interned*/ const char*gtk_css_node_declaration_get_name               (const GtkCssNodeDeclaration   *decl);
 gboolean                gtk_css_node_declaration_set_id                 (GtkCssNodeDeclaration        **decl,
                                                                          const char                    *id);
 const char *            gtk_css_node_declaration_get_id                 (const GtkCssNodeDeclaration   *decl);